<?php
function llenarComboTiposExamen($tiposExamen){
    foreach ($tiposExamen as $row)
    {
        echo "<option value='".$row['Especialidad']."'> ". $row['Descripcion']."</option>";
    }           
}
?>


<script language="javascript" src="<?php echo base_url(); ?>application/views/cirugia/funcionAuxiliares.js"></script>

<form id="ordenForm" class="form-horizontal well"  method="post" action="<?php echo base_url(); ?>cirugia/guardar" accept-charset="utf-8">
    <legend>Orden Preoperatoria</legend>
    <fieldset>
        <div>
            <table   width="700px"><tbody>                
                    <tr>
                        <?php 
                            if(isset($idPreoperatorio)){
                                echo "<td><h5>Nro. $idPreoperatorio</h5></td>";
                            }
                        ?>
                        
                        <td>
                            Estado</td><td>
                            <input name="Estado" class="input-small" type="text"  placeholder="Estado" value='<?php if(isset($estado)){echo $estado;} else echo "Nuevo";?>' readonly="readonly" ></td>
                        <td><p align="right"><font color="black" face="arial" size="+0">
                    <?php if(isset($fecha)){echo $fecha;} else echo "<script language=\"javascript\"> mostrarFecha() </script>";?>
                    
                    </font></p></td>
                
                        </tr>
                        
                    </tbody>
                    </table> 
            <table >
            <tbody>                
                                               
                <tr>
                    <td>Codigo de Paciente</td>
                    <td><input readonly="readonly" id="idPaciente" name="idPaciente"  type="text"  value=<?php if(isset($codPaciente)){echo "'".trim($codPaciente)."'";}else echo"'' placeholder=\"Cod. Paciente\" "?>></td>
                                                          
                </tr>
                <tr>
                   <td>Nombre Paciente</td>
                   <td><input readonly="readonly" id="idnomPa" type="text" value=<?php if(isset($nomPaciente)){echo "'".$nomPaciente."'";}else echo" '' placeholder=\"Nom. Paciente\""?>></td>
                </tr>
                <?php if(!isset($codPaciente))
                       {echo "<tr><td><p><button class=\"btn btn-mini  btn btn-success\" type=\"button\" onclick=\"buscarpaciente()\">Buscar</button></p></td></tr>";}?>
             </tbody>
          </table>           
                <table   ><tbody> 
<!--                     <tr>
                         <td >Edad</td><td><input readonly="readonly"  class="input-mini" type="text"  placeholder="Edad"></td>
                        <td>Sexo</td><td><input readonly="readonly"  class="input-mini"  type="text"  placeholder="Sexo"></td>
                        <td>Peso</td><td><input readonly="readonly"  class="input-mini" type="text"  placeholder="Peso"></td>
                        <td>Talla</td><td><input readonly="readonly"  class="input-mini" type="text"  placeholder="Talla"></td>
                    </tr>   -->
                </tbody>
                </table>
            &nbsp;&nbsp;
                    <table id="tablCuer" width="700px">
                    <tbody > 
                        <caption><h4>Detalles</h4></caption>
                           <thead>
                            <th>Nro. Examen</th>                             
                             <th>Examen</th>
                             <th>Detalle</th>
                             <th>Eliminar</th>                                        
                          </thead>
                          <tr>
                              <td> <button type="button" class="btn btn-mini btn-primary" onclick="agregarFila('intem','tablCuer','tip1','exam1','det1')" >Agregar Item</button></td>
                              <td><select name="Exame" id="exam1" class="span9"> 
                                      <?php llenarComboTiposExamen($Examenes) ?>
                                </select>
                              </td>
                              <td><textarea name="detalle" id="det1" rows="2"></textarea></td>                                                           
                          </tr>
                          <?php 
                            function cortarcadena($corta){
                            if(strlen ($corta)>10){
                                return substr($corta,0,10)."...";        
                            }else return $corta;
                            };
                            
                            if(isset($examenes)){
                                $int=0;
                                foreach ($examenes as $exam) {
                                    $int++;
                                    echo "<tr><td>$int</td>";
                                    $examen=$exam['EspDescrip'];
                                    $valExal=$exam['idEsp'];
                                    echo"<td><label>$examen</label><input type=\"hidden\" name=\"Examenes[]\" value='$valExal'>";
                                    $detalle=$exam['Indic'];                                    
                                    echo"<td><label>".cortarcadena($detalle)."</label><input type=\"hidden\" name=\"detalles[]\" value='$detalle'></td>";
                                    echo "<td><a class=\"btn btn-small\" onclick=\"remove(this)\"><i class=\"icon-remove-sign\"></i></a></td></tr>";                                                                                                                                                
                                }
                                echo "<input type=\"hidden\" id=\"intem\" value=\"$int\"> ";
                            }
                            else echo "<input type=\"hidden\" id=\"intem\" value=\"0\"> ";
                            ?>
                    </tbody>                       
                  </table>   
    </div>
  
    <div class="span10">
         &nbsp;&nbsp;
        <table  class="table table-hover" width="700px">
            <tbody>
                <tr>
                   <td>Codigo de Doctor</td>
                   <td><input id="idcod" name="idDoctor" class="input-small" type="text"  value ="<?php if(isset($codDoct)){echo $codDoct;}?>" onblur="cargaDoctor(this.id,'nomDoc','<?php echo base_url(); ?>application/views/cirugia/CargarDoctor.php')"></td>
                   <td>Nombre de Doctor</td>
                   <td><input readonly="readonly" id="nomDoc" type="text" value="<?php if(isset($nomDoctor)){echo $nomDoctor;}?>" ></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td><button class="btn btn-success" type="submit"  >Guardar</button></td>
                    <td><button class="btn btn-danger" type="button">Cancelar</button></td>
                </tr>
            </tbody>
        </table>
    </div>    
    </fieldset>    
  
</form>


<!-- Modal -->
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display:none;width:700px;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true" onclick="limpiartabla('tablPac')" >×</button>
        <h3 id="myModalLabel">Buscar Persona</h3>
    </div>
    <div class="modal-body" style="height:550px;">
        <div class="control-group">
            <label class="control-label" for="Documento">Documento</label>
            <div class="controls"><input type="text" class="input-xlarge" id="Documento"></div>
        </div>
        <div class="control-group">
            <label class="control-label" for="confNombre">Nombres</label>
            <div class="controls"><input type="text" class="input-xlarge" id="confNombre"></div>
        </div>
        <div class="control-group">
            <label class="control-label" for="ApellidoPat">Apellido Paterno</label>
            <div class="controls"><input type="text" class="input-xlarge" id="ApellidoPat"></div>
        </div>
        <div class="control-group">
            <label class="control-label" for="ApellidoMat">Apellido Materno</label>
            <div class="controls"><input type="text" class="input-xlarge" id="ApellidoMat"></div>
        </div>        
        <div class="control-group">
            <button class="btn btn-mini  btn btn-success" type="button" onclick="realizarbusq('Documento','confNombre','ApellidoMat','ApellidoPat','tablPac','<?php echo base_url(); ?>application/views/cirugia/busqPaciente.php')">Buscar</button>
        </div>        
        <table id="tablPac" class="table table-hover" width="700px">
            <tbody>
            <caption><h4>Pacientes</h4></caption>
                <thead>
                <th>Codigo</th>
                <th>Nombres</th>
                <th>Apellidos</th> 
                </thead>
           </tbody>
          </table>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true" onclick="limpiartabla('tablPac')">Close</button>        
    </div>
</div>
